﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Xml;
using System.Web.UI.WebControls;
using DotNetNuke;
using DotNetNuke.Data;
using DotNetNuke.Entities.Host;
using System.Text;



public partial class DesktopModules_login_login : DotNetNuke.Entities.Modules.PortalModuleBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
       
        
        txtpassword.Attributes.Add("onKeyPress", "javascript:if (event.keyCode == 13) __doPostBack('" + linklogin.UniqueID + "','')");
        
        if (UserId.ToString() != "-1")
        {
            
            pnlsignout.Visible = true;
            pnllogin.Visible = false;
            txtusername.Text = UserInfo.Username.ToString();
            txtpassword.Text = "Password";
            txtusername.Enabled = false;
            txtpassword.Enabled = false;

        }
        else 
        {
            pnlsignout.Visible = false;
            pnllogin.Visible = true;
            linklogin.Focus();
        
        }
        
    }
    protected void linklogin_Click(object sender, EventArgs e)
    {
        DotNetNuke.Security.PortalSecurity users = new DotNetNuke.Security.PortalSecurity();
        string username = txtusername.Text.ToString();
        string password = txtpassword.Text.ToString();
        string portalname = PortalSettings.PortalName.ToString();
        int pid = PortalId;
        int userfound;
         userfound = users.UserLogin(username.ToString(), password.ToString(), pid, portalname, "127.0.0.1", true);
         if (userfound == -1)
         {
             //lblLoginError.Text = "Invalid username or password";
             Page.RegisterClientScriptBlock("!","<script type=\"text/javascript\">alert(\"Username and Password incorrect\");</script>");
         }
         else 
         {
             string currentpage = Page.Request.Url.AbsoluteUri.ToString();
             Response.Redirect(currentpage.ToString());
         
         }
      
        
            
      
        
    }
    protected void linksignout_Click(object sender, EventArgs e)
    {
        DotNetNuke.Security.PortalSecurity signout = new DotNetNuke.Security.PortalSecurity();
        signout.SignOut();
        string currentpage = Page.Request.Url.AbsoluteUri.ToString();
        Response.Redirect(currentpage.ToString());
    }
    protected void loginregister_Click(object sender, EventArgs e)
    {
        string currentpageregister = PortalAlias.HTTPAlias.ToString();//Page.Request.Url.AbsoluteUri.ToString();
        
        Response.Redirect("?ctl=Register");
    }
}
